package com.kd.juhaowan.ui;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.Nullable;


import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallbackProxy;
import com.hjq.toast.ToastUtils;
import com.kd.juhaowan.R;
import com.kd.juhaowan.http.api.LogoffAccountApi;
import com.kd.juhaowan.http.model.HttpData;
import com.kd.juhaowan.http.model.LogoffResult;

import butterknife.BindView;
import butterknife.OnClick;

public class LogoffAccountActivity extends BaseActivity {





    @BindView(R.id.activity_title)
    TextView titleView;
    @BindView(R.id.logoff_account)
    EditText accountView;
    @BindView(R.id.logoff_pwd)
    EditText pwdView;


    @Override
    protected void reInitDate() {
//     initData();
    }
//    public static boolean needRefresh=true;
    private void initData(){
//        needRefresh =false;


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }



    @Override
    protected void onResume() {
        super.onResume();
//        if(needRefresh)initData();
    }

    private void setView(){


    }


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        titleView.setText("账号验证");
//        setContentView(R.layout.activity_account_login);

    }
    @OnClick(R.id.actvity_back)
    public void onBackClick(){
        finish();
    }





    @OnClick(R.id.logoff_account_confirm)
    public void onPasswordClick(){
        String account = accountView.getText().toString().trim();
        String pwd = pwdView.getText().toString().trim();
        if(TextUtils.isEmpty(account)){
            ToastUtils.show("请输入账号");
        }else if(TextUtils.isEmpty(pwd)){
            ToastUtils.show("请输入密码");
        }else{
            EasyHttp.post(this).api(new LogoffAccountApi(account,pwd)).request(new HttpCallbackProxy<HttpData<LogoffResult>>(this){
                @Override
                public void onHttpSuccess(HttpData<LogoffResult> result, boolean cache) {
                    super.onHttpSuccess(result, cache);
                    Intent intent=null;
                    if(1==result.getData().getRealname_check()){
                        intent=new Intent(LogoffAccountActivity.this,LogoffRealnameActivity.class);
                    }else {
                        intent=new Intent(LogoffAccountActivity.this,LogoffFinalActivity.class);
                    }
                    intent.putExtra("model",result.getData());
                    startActivityForResult(intent,10);
                }
        });
        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(10==requestCode&&resultCode==RESULT_OK){
            manager.saveCurrentLoginUserTickit("");
            manager.removeUserAccount(accountView.getText().toString().trim());
            manager.writeAutoLogin(false);
            Intent intent = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        }
    }
    @Override
    protected int getViewLayoutResourceId() {
        return R.layout.activity_logoff_account;
    }




}
